home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpl60n19.zip / ARISOURC.ZIP / F48FRED.ASM < prev    next >
Assembly Source File  |  1993-01-24  |  4KB  |  89 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 6.0        *
  5. ; *     Real Multiple Precision Argument Reduction      *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1991,1992 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   F48FRED
  12.  
  13.              INCLUDE SE.ASM
  14.  
  15.  
  16. CODE         SEGMENT BYTE PUBLIC
  17.  
  18.              ASSUME  CS:CODE
  19.  
  20. ; Externals
  21.  
  22.              EXTRN   RealAdd:NEAR,RealMulNoChk:NEAR,RealMul:NEAR
  23.  
  24. ; Publics
  25.  
  26.              PUBLIC  RealReduceMP
  27.  
  28.  
  29. ;-----------------------------------------------------------------------------
  30. ; Routine RealReduceMP realizes an extended precision argument reduction as
  31. ; needed in the calculation of trigonometric functions Sin, Cos, and Tan and
  32. ; in the Exp function. In the argument reduction for these functions there is
  33. ; the danger of a great loss of precision due to cancelling when subtracting
  34. ; numbers of nearly equal magnitude. The reduction usually calls for the
  35. ; subtraction of some multiple n of a constant c from the argument x. The
  36. ; precision can be increased if the constant is split into two parts, c1 and
  37. ; c2, with c1 being the most significant part and c2 being the least
  38. ; significant part and c1+c2=c with more bits of precision than there are
  39. ; bits in the mantissa of the floating point format used for the calculations.
  40. ; Instead of computing x - n*c, the calculation is done as x - n*c1 - n*c2,
  41. ; where it is important that n*c1 can be exactly represented in the floating
  42. ; point format used.
  43. ;
  44. ; INPUT:     DX:BX:AX  n
  45. ;            DI:SI:CX  x
  46. ;            CS:BP     Pointer to table containing two REAL constants c1,c2
  47. ;
  48. ; OUTPUT:    DX:BX:AX  x + n*c1 + n*c2
  49. ;
  50. ; DESTROYS:  AX,BX,CX,DX,SI,DI,Flags
  51. ;------------------------------------------------------------------------------
  52.  
  53. RealReduceMP PROC    NEAR
  54.              PUSH    DX                ; save
  55.              PUSH    BX                ;  n on
  56.              PUSH    AX                ;   stack
  57.              PUSH    DI                ; save x
  58.              PUSH    SI                ;  on
  59.              PUSH    CX                ;   stack
  60.              MOV     CX, CS:[BP+0]     ; get c1
  61.              MOV     SI, CS:[BP+2]     ;  from constant table
  62.              MOV     DI, CS:[BP+4]     ;   pointed to by CS:BP
  63.              CALL    RealMulNoChk      ; compute n*c1
  64.              POP     CX                ; get
  65.              POP     SI                ;  back
  66.              POP     DI                ;   x
  67.              CALL    RealAdd           ; compute x + n*c1
  68.              POP     CX                ; get
  69.              POP     SI                ;  back
  70.              POP     DI                ;   n
  71.              PUSH    DX                ; save
  72.              PUSH    BX                ;  x + n*c1
  73.              PUSH    AX                ;   on stack
  74.              MOV     AX, CS:[BP+6]     ; get
  75.              MOV     BX, CS:[BP+8]     ;  c2 from
  76.              MOV     DX, CS:[BP+10]    ;   constant table
  77.              CALL    RealMul           ; compute n*c2
  78.              POP     CX                ; get
  79.              POP     SI                ;  back
  80.              POP     DI                ;   x + n*c1
  81.              JMP     RealAdd           ; compute x + n*c1 + n*c2 and return
  82. RealReduceMP ENDP
  83.  
  84.              ALIGN   4
  85.  
  86. CODE         ENDS
  87.  
  88.              END
  89.